/*
**  Copyright (c) 2014 Michael Liu(michael.liu.point@gmail.com).
**
**  Project: Gateway Unified Management Platform
**  File:    dpmgr.h
**  Author:  Michael
**  Date:    03/20/2014
**
**  Purpose:
**    data path management defines.
*/

#ifndef __DATAPATHMGR_H__
#define __DATAPATHMGR_H__

#ifdef __cplusplus
extern "C" {
#endif				/* __cplusplus */

/* Include files. */

#include "common.h"
#include "cmrc.h"
#include "list.h"
#include "dpif.h"
#include "dpdev.h"
#include "dprule.h"
#include "dpcmn.h"

/* Macro constant definitions. */

#define SYSTEM_DATA_PATH_MAX			2
#define SYSTEM_DEFAULT_DP				0

#define SYSTEM_REPEATER_DP_24G			0
#define SYSTEM_REPEATER_DP_5G			1

#define DP_WORK_NAME_STR_MAX			32

#define DP_IF_WPS_WORK_SUBFIX			"_wps_work"
#define DP_IF_LED_WORK_SUBFIX			"_led_work"

/* Type definitions. */

	enum {
		eDP_MODE_ROUTER,
		eDP_MODE_BRIDGE_AP,
		eDP_MODE_BRIDGE_REPEATER,
	} edp_mode;

	enum {
		eDP_SUB_MOD_DP_COMMON,
		eDP_SUB_MOD_DP_IF,
		eDP_SUB_MOD_DP_RULE,
	} edp_sub_module;

	enum {
		eDP_CMD_OPT_ADD_WORK,
		eDP_CMD_OPT_DEL_WORK,
	} edp_cmd_opt;

	typedef struct dp_work tdp_work;
	struct dp_work {
		char name[DP_WORK_NAME_STR_MAX];
		struct list_head list;
		unsigned char done;
		void (*work) (tdp_work * me, void *arg);
		void *arg;
	};

	typedef struct dp_cmd tdp_cmd;
	struct dp_cmd {
		struct list_head list;
		int cmd_opt;
		union {
			tdp_work work;
		};
	};

	struct data_paths {
		unsigned char mode;	/* edp_mode */
		struct list_head all_ifs;
		struct list_head net_ifs[SYSTEM_DATA_PATH_MAX];
		tdp_rule dp_rules;
		void *priv;
	};

	typedef struct cm_dp_opt_body tcm_dp_req_body;
	typedef struct cm_dp_opt_body tcm_dp_rsp_body;
	struct cm_dp_opt_body {
		unsigned char submod;	/* indicate req_body type:edp_sub_module */
		unsigned char body[0];	/* tcm_dp_if_req_body or tcm_dp_rule_req_body */
	};

	typedef struct cm_dp_cmn_opt_body tcm_dp_cmn_req_body;
	typedef struct cm_dp_cmn_opt_body tcm_dp_cmn_rsp_body;

	struct cm_dp_cmn_opt_body {
		unsigned char opt;	/* indicate body type, edp_cmn_opt. */
		union {
			unsigned char mode;	/* edp_mode */
			unsigned int country_number;
			tdevmac devmac;
		};
	};

	typedef struct cm_dp_if_opt_body tcm_dp_if_req_body;
	typedef struct cm_dp_if_opt_body tcm_dp_if_rsp_body;

	struct cm_dp_if_opt_body {
		char name[DP_IF_NAMESIZE];
		unsigned char opt;	/* indicate body type, edp_if_method. */
		tmask mask;	/* indicate operation mask. */
		/*
		 ** body:
		 **   opt - eDP_IF_REQ_OPT_SET_LINKCFG and eDP_IF_REQ_OPT_GET_LINKCFG:
		 **    - twlan_cli_if_linkcfg
		 **    - twlan_ap_if_linkcfg
		 **    - tvlan_if_linkcfg
		 **    - teth_if_linkcfg
		 **    - tbridge_if_linkcfg
		 **   opt - eDP_IF_REQ_OPT_GET_LINKSTAT:
		 **    - unsigned char linkstatus for normal.
		 **    - mask & eWLAN_LINKSTAT_MASK0_QUERY /CANCEL
		 **      -- twlan_cli_if_link_status if interface == wlan cli. means scan ap list.
		 **      -- twlan_ap_if_link_status if interface == wlan ap. means get client list.
		 **   opt - eDP_IF_REQ_OPT_SET_NETCFG and eDP_IF_REQ_OPT_GET_NETCFG:
		 **    - tdp_if_netcfg
		 */
		unsigned char body[0];
	};

	typedef struct cm_dp_rule_opt_body tcm_dp_rule_req_body;
	typedef struct cm_dp_rule_opt_body tcm_dp_rule_rsp_body;
	struct cm_dp_rule_opt_body {
		unsigned char opt;	/* indicate body type. */
		unsigned char body[0];	/*  */
	};

/* External function declarations. */

	extern e_ret data_path_init(tdata_paths * dp);
	extern e_ret data_path_start(void);
	extern e_ret data_path_proc_req(tcm_req_body * req, tcm_rsp_body ** rsp);

	extern e_ret dpif_update_dhcpd_cfg(tdp_if * dp_if);
	extern e_ret dpif_update_dns_addr_cfg(void *dp_rule);

	extern e_ret dp_task_opt_work(tdata_paths * dp, tdp_work * work, e_bool add);

	extern e_ret dp_wlan_wps_proc(unsigned char button_event);

/* Macro API definitions. */

#define dp_task_add_work(dp, work) dp_task_opt_work((dp), (work), eBOOL_TRUE)
#define dp_task_del_work(dp, work) dp_task_opt_work((dp), (work), eBOOL_FALSE)

/* Global variable declarations. */

#ifdef __cplusplus
}				/* extern "C" */
#endif				/* __cplusplus */
#endif				/* __DATAPATHMGR_H__ */
